package com.luke.web.controller.base;

import com.luke.base.domain.LkQuestion;
import com.luke.base.service.ILkQuestionService;
import com.luke.common.annotation.Log;
import com.luke.common.core.controller.BaseController;
import com.luke.common.core.domain.AjaxResult;
import com.luke.common.core.page.TableDataInfo;
import com.luke.common.enums.BusinessType;
import com.luke.common.utils.poi.ExcelUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 在线问答Controller
 * 
 * @author luke
 * @date 2021-05-25
 */
@RestController
@RequestMapping("/base/question")
public class LkQuestionController extends BaseController
{
    @Autowired
    private ILkQuestionService lkQuestionService;

    /**
     * 查询在线问答列表
     */
    @PreAuthorize("@ss.hasPermi('base:question:list')")
    @GetMapping("/list")
    public TableDataInfo list(LkQuestion lkQuestion)
    {
        startPage();
        List<LkQuestion> list = lkQuestionService.selectLkQuestionList(lkQuestion);
        return getDataTable(list);
    }

    /**
     * 导出在线问答列表
     */
    @PreAuthorize("@ss.hasPermi('base:question:export')")
    @Log(title = "在线问答", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(LkQuestion lkQuestion)
    {
        List<LkQuestion> list = lkQuestionService.selectLkQuestionList(lkQuestion);
        ExcelUtil<LkQuestion> util = new ExcelUtil<LkQuestion>(LkQuestion.class);
        return util.exportExcel(list, "在线问答数据");
    }

    /**
     * 获取在线问答详细信息
     */
    @PreAuthorize("@ss.hasPermi('base:question:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id)
    {
        return AjaxResult.success(lkQuestionService.selectLkQuestionById(id));
    }

    /**
     * 新增在线问答
     */
    @PreAuthorize("@ss.hasPermi('base:question:add')")
    @Log(title = "在线问答", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody LkQuestion lkQuestion)
    {
        return toAjax(lkQuestionService.insertLkQuestion(lkQuestion));
    }

    /**
     * 修改在线问答
     */
    @PreAuthorize("@ss.hasPermi('base:question:edit')")
    @Log(title = "在线问答", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody LkQuestion lkQuestion)
    {
        return toAjax(lkQuestionService.updateLkQuestion(lkQuestion));
    }

    /**
     * 删除在线问答
     */
    @PreAuthorize("@ss.hasPermi('base:question:remove')")
    @Log(title = "在线问答", businessType = BusinessType.DELETE)
	@DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids)
    {
        return toAjax(lkQuestionService.deleteLkQuestionByIds(ids));
    }
}
